/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI_Busquedas;

import AccesoBusquedas.AB_Proveedor;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
 *
 * @author Cyber Huevadictos
 */
public class Frm_busq_proveedor extends javax.swing.JDialog {
    private  AB_Proveedor obj;
    private String objcadena;

    /**
     * Creates new form Frm_busq_proveedor
     */
    public Frm_busq_proveedor(java.awt.Frame parent, boolean modal, String objcadena) throws Exception{
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        //        
        obj = new AB_Proveedor();
         setObjcadena(objcadena);
         jTableBusqueda.setModel(obj.TProveedor(null, 0));
         jTableBusqueda.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          //evento escuchador
         jTableBusqueda.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() {
            @Override
                    public void valueChanged(ListSelectionEvent event) {
                try {
                    jTableAccion(event);
                } catch (Exception ex) {
                    Logger.getLogger(Frm_busq_clientes.class.getName()).log(Level.SEVERE, null, ex);
                }
                    }
         });
    }
    private void jTableAccion(javax.swing.event.ListSelectionEvent evt) throws Exception {
        int filas = jTableBusqueda.getSelectedRow();
        this.objcadena = jTableBusqueda.getValueAt(filas, 0).toString();
        setObjcadena(this.objcadena);
        //cConexion.cerrar();
        dispose();
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableBusqueda = new javax.swing.JTable();
        jPanelOpciones = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jLabelImagen = new javax.swing.JLabel();
        jPanelFiltros = new javax.swing.JPanel();
        jLabelOp1 = new javax.swing.JLabel();
        jTextFieldOp1 = new javax.swing.JTextField();
        jLabelOp2 = new javax.swing.JLabel();
        jTextFieldOp2 = new javax.swing.JTextField();
        jLabelOp3 = new javax.swing.JLabel();
        jTextFieldOp3 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("BUSQUEDA DE PRODUCTOS");

        jTableBusqueda.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTableBusqueda);

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jScrollPane1)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 224, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        jPanelOpciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opciones de Busqueda", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 18))); // NOI18N

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButton1.setText("EMPRESA");
        jRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButton1MouseClicked(evt);
            }
        });
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButton2.setText("REPRESENTANTE");
        jRadioButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButton2MouseClicked(evt);
            }
        });

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButton3.setText("CIUDAD");
        jRadioButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButton3MouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelOpcionesLayout = new org.jdesktop.layout.GroupLayout(jPanelOpciones);
        jPanelOpciones.setLayout(jPanelOpcionesLayout);
        jPanelOpcionesLayout.setHorizontalGroup(
            jPanelOpcionesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelOpcionesLayout.createSequentialGroup()
                .addContainerGap()
                .add(jRadioButton1)
                .add(52, 52, 52)
                .add(jRadioButton2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 50, Short.MAX_VALUE)
                .add(jRadioButton3)
                .addContainerGap())
        );
        jPanelOpcionesLayout.setVerticalGroup(
            jPanelOpcionesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelOpcionesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jRadioButton1)
                .add(jRadioButton2)
                .add(jRadioButton3))
        );

        jLabelImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/32Nuvola_search_person.png"))); // NOI18N

        jPanelFiltros.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabelOp1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelOp1.setText("EMPRESA:");

        jTextFieldOp1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldOp1.setEnabled(false);
        jTextFieldOp1.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldOp1CaretUpdate(evt);
            }
        });
        jTextFieldOp1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldOp1KeyTyped(evt);
            }
        });

        jLabelOp2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelOp2.setText("REPRESENTANTE:");

        jTextFieldOp2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldOp2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTextFieldOp2.setEnabled(false);
        jTextFieldOp2.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldOp2CaretUpdate(evt);
            }
        });
        jTextFieldOp2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldOp2KeyTyped(evt);
            }
        });

        jLabelOp3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelOp3.setText("CIUDAD");

        jTextFieldOp3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldOp3.setEnabled(false);
        jTextFieldOp3.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldOp3CaretUpdate(evt);
            }
        });
        jTextFieldOp3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldOp3KeyTyped(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelFiltrosLayout = new org.jdesktop.layout.GroupLayout(jPanelFiltros);
        jPanelFiltros.setLayout(jPanelFiltrosLayout);
        jPanelFiltrosLayout.setHorizontalGroup(
            jPanelFiltrosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelFiltrosLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelFiltrosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabelOp1)
                    .add(jLabelOp2)
                    .add(jLabelOp3))
                .add(32, 32, 32)
                .add(jPanelFiltrosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jTextFieldOp2)
                    .add(jTextFieldOp3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
                    .add(jTextFieldOp1))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelFiltrosLayout.setVerticalGroup(
            jPanelFiltrosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelFiltrosLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelFiltrosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelOp1)
                    .add(jTextFieldOp1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanelFiltrosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelOp2)
                    .add(jTextFieldOp2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanelFiltrosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelOp3)
                    .add(jTextFieldOp3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(58, 58, 58)
                .add(jLabelImagen)
                .add(18, 18, 18)
                .add(jPanelOpciones, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(71, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(79, 79, 79)
                        .add(jPanelFiltros, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanelOpciones, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabelImagen)
                        .add(12, 12, 12)))
                .add(18, 18, 18)
                .add(jPanelFiltros, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton1MouseClicked
        // TODO add your handling code here:
        jTextFieldOp1.setEnabled(true);
        jTextFieldOp2.setEnabled(false);
        jTextFieldOp3.setEnabled(false);
    }//GEN-LAST:event_jRadioButton1MouseClicked

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton2MouseClicked
        // TODO add your handling code here:
        jTextFieldOp1.setEnabled(false);
        jTextFieldOp2.setEnabled(true);
        jTextFieldOp3.setEnabled(false);
    }//GEN-LAST:event_jRadioButton2MouseClicked

    private void jRadioButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton3MouseClicked
        // TODO add your handling code here:
        jTextFieldOp1.setEnabled(false);
        jTextFieldOp2.setEnabled(false);
        jTextFieldOp3.setEnabled(true);
    }//GEN-LAST:event_jRadioButton3MouseClicked

    private void jTextFieldOp1CaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldOp1CaretUpdate
        // TODO add your handling code here:
        try{
            jTableBusqueda.setModel(obj.TProveedor(this.jTextFieldOp1.getText().trim().toUpperCase(), 1));
        }catch(Exception ex){}
    }//GEN-LAST:event_jTextFieldOp1CaretUpdate

    private void jTextFieldOp1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldOp1KeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= 'A' && t <= 'Z') || (t == ' ') || (t == 'Ñ') || (t == 'é') || (t == 'í') || (t == 'ó') || (t == 'ú') || (t == 'á') || (t == 'ñ') || ((t >= 'a' && t <= 'z'))) || jTextFieldOp1.getText().length() > 50) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldOp1KeyTyped

    private void jTextFieldOp2CaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldOp2CaretUpdate
        // TODO add your handling code here:
        try{
            jTableBusqueda.setModel(obj.TProveedor(this.jTextFieldOp2.getText().trim().toUpperCase(), 2));
        }catch(Exception ex){}
    }//GEN-LAST:event_jTextFieldOp2CaretUpdate

    private void jTextFieldOp2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldOp2KeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= 'A' && t <= 'Z') || (t == ' ') || (t == 'Ñ') || (t == 'é') || (t == 'í') || (t == 'ó') || (t == 'ú') || (t == 'á') || (t == 'ñ') || ((t >= 'a' && t <= 'z'))) || jTextFieldOp2.getText().length() > 50) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldOp2KeyTyped

    private void jTextFieldOp3CaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldOp3CaretUpdate
        // TODO add your handling code here:
        try{
            jTableBusqueda.setModel(obj.TProveedor(this.jTextFieldOp3.getText().trim().toUpperCase(), 3));
        }catch(Exception ex){}
    }//GEN-LAST:event_jTextFieldOp3CaretUpdate

    private void jTextFieldOp3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldOp3KeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= 'A' && t <= 'Z') || (t == ' ') || (t == 'Ñ') || (t == 'é') || (t == 'í') || (t == 'ó') || (t == 'ú') || (t == 'á') || (t == 'ñ') || ((t >= 'a' && t <= 'z'))) || jTextFieldOp3.getText().length() > 50) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldOp3KeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Frm_busq_proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frm_busq_proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frm_busq_proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frm_busq_proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try{
                    Frm_busq_proveedor dialog = new Frm_busq_proveedor(new javax.swing.JFrame(), true, "");
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                        @Override
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                }catch(Exception ex){}
                //new Frm_busq_proveedor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabelImagen;
    private javax.swing.JLabel jLabelOp1;
    private javax.swing.JLabel jLabelOp2;
    private javax.swing.JLabel jLabelOp3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelFiltros;
    private javax.swing.JPanel jPanelOpciones;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableBusqueda;
    private javax.swing.JTextField jTextFieldOp1;
    private javax.swing.JTextField jTextFieldOp2;
    private javax.swing.JTextField jTextFieldOp3;
    // End of variables declaration//GEN-END:variables
    public String getObjcadena() {
        return objcadena;
    }

    public void setObjcadena(String objcadena) {
        this.objcadena = objcadena;
    }
}
